//
//  SameWay.m
//  K-Music
//
//  Created by 林杰良 on 16/1/5.
//  Copyright © 2016年 CHUN. All rights reserved.
//

#import "SameWay.h"

@implementation SameWay
+(void)downloadData:(NSString*)values andCallback:(MyCallback)callback{
    NSString*infoStr11;

    if ([values isEqualToString:@"A"]) {
        //全国最火
        infoStr11=[NSString stringWithFormat:@"/api/records?page=0&size=20&sort=totalPlay,DESC"];
        
    }else if([values isEqualToString:@"B"]){
        //本月最火
        infoStr11=[NSString stringWithFormat:@"/api/records?page=0&size=20&sort=totalPlayMonthly,DESC"];
        
    }else if([values isEqualToString:@"C"]){
        //最火歌手总榜
        infoStr11=[NSString stringWithFormat:@"/api/users/detail?page=0&size=7&sort=fanNumber,DESC"];
        
    }else if([values isEqualToString:@"D"]){
        //本月最火歌手榜
        infoStr11=[NSString stringWithFormat:@"/api/users/detail?page=0&size=7&sort=fanNumberMonthly,DESC"];
        
    }else if([values isEqualToString:@"E"]){
        //财富总榜
        infoStr11=[NSString stringWithFormat:@"/api/users/detail?page=0&size=20&sort=consumedNumber,DESC"];
        
    }else if([values isEqualToString:@"F"]){
        //本月财富
        infoStr11=[NSString stringWithFormat:@"/api/users/detail?page=0&size=20&sort=consumedNumberMonthly,DESC"];
    }
    
    AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
    
    NSString *intactURL = [MyBaseUrl stringByAppendingString:infoStr11];
    
    NSString * token = [FileStorage NSUserDefault_getObjectForKey:access_token];
    
    manager.requestSerializer =[AFHTTPRequestSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json"
                     forHTTPHeaderField:@"Accept"];
    [manager.requestSerializer setValue:[NSString stringWithFormat: @"Bearer %@",token]
                     forHTTPHeaderField:@"Authorization"];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager GET:intactURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary*dic=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        
        NSLog(@"成功GET --> %@", dic);
        
        NSMutableArray*array=[NSMutableArray array];
        
        NSLog(@"resultCode:%@",dic[@"resultCode"]);
        NSArray*content=dic[@"body"][@"content"];
        
        NSArray * Datas = [A_Music objectArrayWithKeyValuesArray:content];
        array = [NSMutableArray arrayWithArray:Datas];
        
        callback(array);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"%@",error);
        
    }];
}

@end
